// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path')
function resolve (dir) {
  return path.join(__dirname, '.', dir)
}

module.exports = {
  // devServer: {
  //   proxy: {
  //     '/api': {
  //       target: process.env.VUE_APP_API_URL,
  //       changeOrigin: true,
  //       pathRewrite: {
  //         '^/api': ''
  //       }
  //     }
  //   }
  // },
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
      // List native deps here if they don't work
      // externals: ['my-native-dep'],
      // If you are using Yarn Workspaces, you may have multiple node_modules folders
      // List them all here so that VCP Electron Builder can find them
      // nodeModulesPath: ['./node_modules'],
      builderOptions: {
        appId: 'com.rawa.documet.desktop',
        productName: '玖钉文档系统', // 项目名，也是生成的安装文件名，即aDemo.exe
        copyright: 'Copyright © 2021', // 版权信息
        win: {
          icon: './public/app.png', // 安装包图标
          target: [
            {
              target: 'nsis',
              arch: [
                'x64',
                'ia32'
              ]
            }
          ]
        },
        mac: {
          icon: './public/app.png',
          target: [
            {
              target: 'dmg',
              arch: [
                'x64',
                'arm64'
              ]
            }
          ]
        },
        linux: {
          icon: './public/app.png',
          target: [
            {
              target: 'AppImage',
              arch: [
                'x64',
                'arm64'
              ]
            }
          ]
        }
      }
    }
  },
  chainWebpack: config => {
    config.module
      .rule('svg')
      .exclude.add(resolve('src/plugins/svg/src/icons'))
      .end()

    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/plugins/svg/src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .tap(options => {
        options = {
          symbolId: 'icon-[name]'
        }
        return options
      })

    config.module
      .rule('node')
      .test(/\.node$/)
      .use('node-loader')
      .loader('node-loader')
      .end()

    config
      .plugin('html')
      .tap(args => {
        args[0].title = process.env.VUE_APP_TITLE
        return args
      })
  }
}
